<template>
  <a-spin :spinning="loading">
    <page-layout :title="getTitle" style="margin-top: 20px">
      <div slot="action">
<!--        <a-button style="margin-left: 20px" :icon="this.getIconShow" @click="showButtomShow"> {{ this.getButtomShow }}</a-button>-->
        <a-button v-show="teacherBaseInfo.teacherType=='1-1' && !isview " type="primary" icon="download" @click="handleExport()">导出考核登记表</a-button>
      </div>
      <div slot="headerContent">
        <detail-list  size="small" :col="3" class="detail-layout">
          <detail-list-item term="姓名">{{teacherBaseInfo.realname}}</detail-list-item>
          <detail-list-item term="年龄">{{ this.getAge }}</detail-list-item>
          <detail-list-item term="性别">{{teacherBaseInfo.sex_dictText}}</detail-list-item>
          <detail-list-item term="部门">{{ teacherBaseInfo.orgCode_dictText }}</detail-list-item>
          <detail-list-item term="职称">{{ teacherBaseInfo.titleDescribe }}</detail-list-item>
          <detail-list-item term="职务">{{ teacherBaseInfo.positionDescribe }}</detail-list-item>
        </detail-list>
        <a-divider dashed />
        <a-row style="margin-bottom: 20px" v-if="teacherBaseInfo.teacherType=='1-1'">
          <a-col  :sm="4" :xs="12">
            <head-info title="教学数量" :content="this.teacherScore.classTime.score + ''" :bordered="true"/>
          </a-col>
          <a-col :sm="4" :xs="12">
            <head-info title="教学建设" :content="this.teacherScore.teachingBuild.score + ''" :bordered="true"/>
          </a-col>
          <a-col :sm="4" :xs="12">
            <head-info title="奖励荣誉" :content="this.teacherScore.honour.score + ''" :bordered="true"/>
          </a-col>
          <a-col :sm="4" :xs="12">
            <head-info title="科研" :content="this.teacherScore.research.score + ''" :bordered="true"/>
          </a-col>
          <a-col :sm="5" :xs="12">
            <head-info title="育人与服务" :content="this.teacherScore.educationAndService.score + ''" />
          </a-col>
        </a-row>
        <a-row style="margin-bottom: 20px" v-else>

          <a-col :sm="8" :xs="12">
            <head-info title="教学建设" :content="this.teacherScore.teachingBuild.score + ''" :bordered="true"/>
          </a-col>
          <a-col :sm="8" :xs="12">
            <head-info title="奖励荣誉" :content="this.teacherScore.honour.score + ''" :bordered="true"/>
          </a-col>
          <a-col :sm="8" :xs="12">
            <head-info title="科研" :content="this.teacherScore.research.score + ''" />
          </a-col>

        </a-row>
      </div>
      <teacher-result-total-score :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :total-score="this.teacherScore.totalScore" :total-org-ranked="this.teacherScore.totalOrgRanked" :teacher-type="teacherBaseInfo.teacherType" slot="extra"></teacher-result-total-score>
      <teacher-result-class-time v-if="teacherBaseInfo.teacherType=='1-1'" :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :score="this.teacherScore.classTime" :teacher-type="teacherBaseInfo.teacherType"></teacher-result-class-time>
      <teacher-result-building :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :score="this.teacherScore.teachingBuild" :teacher-type="teacherBaseInfo.teacherType"></teacher-result-building>
      <teacher-result-honour :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :score="this.teacherScore.honour" :teacher-type="teacherBaseInfo.teacherType"></teacher-result-honour>
<!--&lt;!&ndash;      <teacher-result-research :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :score="this.teacherScore.research"></teacher-result-research>&ndash;&gt;-->
      <teacher-result-researchGL :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :score="this.teacherScore.research" :teacher-type="teacherBaseInfo.teacherType"></teacher-result-researchGL>
      <teacher-result-service v-if="teacherBaseInfo.teacherType=='1-1'" :user-name="this.userName" :date='this.date' :teacher-count="this.teacherCount" :score="this.teacherScore.educationAndService"></teacher-result-service>
    </page-layout>
  </a-spin>

</template>

<script>
import HeadInfo from '@/components/tools/HeadInfo'
import PageLayout from '@/components/page/PageLayout'
import DetailList from '@/components/tools/DetailList'
import TeacherResultRadar from '@views/gfxy/result/modules/teacherResultRadar'
import TeacherResultClassTime from '@views/gfxy/result/modules/teacherResultClasstime'
import TeacherResultBuilding from '@views/gfxy/result/modules/teacherResultBuilding'
import TeacherResultHonour from '@views/gfxy/result/modules/teacherResultHonour'
import TeacherResultResearch from '@views/gfxy/result/modules/teacherResultResearch'
import TeacherResultResearchGL from '@views/gfxy/result/modules/teacherResultResearchGL'
import TeacherResultService from '@views/gfxy/result/modules/teacherResultService'
import teacherResultRanking from '@views/gfxy/result/modules/teacherResultRanking'
import teacherResultTotalScore from '@views/gfxy/result/modules/teacherResultTotalScore'
import moment from 'moment'
import { downFile, getAction } from '@api/manage'

const DetailListItem = DetailList.Item

export default {
  name: "teacherResultDetail",
  props: {
    userName: {
      type: String,
      required: true
    },
    date: {
      type: String,
      required: true
    },
    teacherCount:{
      type: Object,
      required: true
    },
    teacherBaseInfo:{
      type: Object,
      required: true
    },
    isview:{
      type:Boolean,
      default: false,
    }
  },
  components: {
    TeacherResultService,
    TeacherResultResearch,
    TeacherResultResearchGL,
    TeacherResultBuilding,
    TeacherResultHonour,
    TeacherResultClassTime,
    TeacherResultRadar,
    teacherResultRanking,
    PageLayout,
    DetailList,
    teacherResultTotalScore,
    DetailListItem,
    HeadInfo
  },
  data(){
    return {
      loading: false,
      teacherScore:{
        classTime:{
          score:'0',
          orgRanked:'0',
          shcoolRanked:'0'
        },
        teachingBuild:{
          score:'0',
          orgRanked:'0',
          shcoolRanked:'0'
        },
        honour:{
          score:'0',
          orgRanked:'0',
          shcoolRanked:'0'
        },
        research:{
          score:'0',
          orgRanked:'0',
          shcoolRanked:'0'
        },
        researchGL:{
          score:'0',
          orgRanked:'0',
          shcoolRanked:'0'
        },
        educationAndService:{
          score:'0',
          orgRanked:'0',
          shcoolRanked:'0'
        },
        totalScore:'0',
        totalOrgRanked:'0'

      },
      // teacherBaseInfo:{},
      url:{
        getTeacherScoreUrl:'index/teacherIndex/getTeacherScoreAndRankedByUsernameAndDate',
        getTeacherBaseInfoUrl:'index/teacherIndex/getTeacherBaseInfoByUserName',
        handleExportXlsTemplate: 'index/teacherIndex/exportDoc'
      }
    }
  },
  computed:{
    getAge(){
      let birthday = moment(this.teacherBaseInfo.birthday).format('YYYY-MM-DD')
      let age = moment().diff(birthday, 'years')
      return age
    },
    getTitle(){
      return this.teacherBaseInfo.realname + "(" + this.userName + ")"
    }
  },
  methods: {
    initTeacherScore(){
      getAction(this.url.getTeacherScoreUrl, { date:this.date, username: this.userName,orgCode:this.teacherBaseInfo.orgCode}).then((res) => {
        console.log(res)
        if (res.success) {
          console.log("initTeacherScore",res.result)
          this.teacherScore = res.result;

        }
        getAction('/research/researchKygl/totalScore',{ date:this.date, workNo:this.userName}).then((res) =>{
          this.teacherScore.researchGL.score = res.result.totalScore
        })
      }).finally(() => {
        this.loading = false;
      })
    },

    handleExport(){
      let fileName = "事业单位工作人员年度考核登记表.docx";
      let param = {teacherId: this.userName}

      console.log("导出参数",param)
      downFile(this.url.handleExportXlsTemplate,param).then((data)=>{
        if (!data) {
          this.$message.warning("文件下载失败")
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data],{type: 'application/msword'}), fileName)
        }else{
          let url = window.URL.createObjectURL(new Blob([data],{type: 'application/msword'}))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName)
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下载完成移除元素
          window.URL.revokeObjectURL(url); //释放掉blob对象
        }
      })
    }
  },
  created() {
    this.initTeacherScore();

  }
}
</script>

<style lang="less" scoped>
  .detail-layout {
    margin-left: 44px;
  }
  .text {
    color: rgba(0, 0, 0, .45);
  }

  .heading {
    color: rgba(0, 0, 0, .85);
    font-size: 20px;
  }

  .no-data {
    color: rgba(0, 0, 0, .25);
    text-align: center;
    line-height: 64px;
    font-size: 16px;

    i {
      font-size: 24px;
      margin-right: 16px;
      position: relative;
      top: 3px;
    }
  }

  .mobile {
    .detail-layout {
      margin-left: unset;
    }
    .text {

    }
    .status-list {
      text-align: left;
    }
  }



</style>